var vm = new Vue({
    // 选项
    el: '#rrapp',
    data: {
        columns1: [
            {
                title: '待办事项',
                key: 'TYPE',
                align: 'center',
            },
            {
                title: '项数',
                key: 'TYPENUMBER',
                align: 'center',
            }
        ],
        data1: [],
        allDataColumns: [
            {
                type: 'selection',
                width: 60,
                align: 'center'
            },
            {
                title: '标题',
                key: 'TITLE',
                align: 'center',
            }, {
                title: '所属车间',
                key: 'NAME',
                align: 'center',
            }, {
                title: '提交时间',
                key: 'STARTDATE',
                align: 'center',
            }, {
                title: '消息状态',
                key: 'READ_DESC',
                align: 'center'
            }, {
                title: '备注',
                key: 'REMARK',
                align: 'center',
            }
        ],
        allData: [],
        menuList: {},
    },
    // 在组件中
    methods: {
        dataTable: function (allData) {
            var _this = this;
            Ajax.request({
                url: '../sysMsg/queryMsgDataResource',
                params: {type: sysEnums.MSG_TYPE_REVERSAL[allData.TYPE]},
                async: true,
                successCallback: function (res) {
                    _this.allData = [];
                    for (var i = 0; i < res.list.length; i++) {
                        const dataResource = res.list[i];
                        _this.allData.push(dataResource);
                    }
                    openWindow({
                        title: allData.TYPE,
                        // area: ['350px', '200px'],
                        content: jQuery("#allData"),
                        btn: ['取消'],
                        btn1: function (index) {
                            layer.close(index);
                        },

                    })
                }
            })
        },
        allReaded: function(){
            let _this = this;
            // 已读所有选中先
            let data = this.$refs.msgItemTable.getSelection();
            if(data.length == 0){
                layer.alert("请选中消息记录！", {icon: 5});
                return;
            }
            let msgIdList = [];
            for (let i = 0; i < data.length; i++) {
                msgIdList.push(data[i].ID);
            }
            Ajax.request({
                url: '../sysMsg/messageReaded',
                params: {'msgIdList':msgIdList},
                type: "POST",
                successCallback: function (r) {
                    alert('标记已读成功', function (index) {
                        for (let i = 0; i < _this.allData.length; i++) {
                            for (let j = 0; j < data.length; j++) {
                                if(_this.allData[i].ID == data[j].ID){
                                    _this.allData[i].READ_DESC = '已处理';
                                }
                            }
                        }
                    });
                }
            });
        },
        allDelete: function(){
            let _this = this;
            // 已读所有选中先
            let data = this.$refs.msgItemTable.getSelection();
            if(data.length == 0){
                layer.alert("请选中消息记录！", {icon: 5});
                return;
            }
            let msgIdList = [];
            for (let i = 0; i < data.length; i++) {
                msgIdList.push(data[i].ID);
            }
            Ajax.request({
                url: '../sysMsg/batchDelete',
                params: {'msgIdList':msgIdList},
                type: "POST",
                successCallback: function (r) {
                    alert('批量删除成功', function (index) {
                        // 获取当前数组中的元素
                        let newArr = [];
                        outer:for (let i = 0; i < _this.allData.length; i++) {
                            inner:for (let j = 0; j < data.length; j++) {
                                if(_this.allData[i].ID == data[j].ID){
                                    continue outer;
                                }
                            }
                            newArr.push(_this.allData[i]);
                        }
                        _this.allData = newArr;
                    });
                }
            });
        },
        allDataTable: function (indexDataUrl) {
            if (!indexDataUrl.DATA_URL) {
                alert("路径错误,暂不可访问");
            } else {
                // 打开消息页面，同时更新状态
                openWindow({
                    title: indexDataUrl.TITLE,
                    type: 2,
                    content: indexDataUrl.DATA_URL
                })
                $.ajax({
                    url: '../sysMsg/upMsgDataResource',
                    type: 'post',
                    data: {'id': indexDataUrl.ID, 'dataId': indexDataUrl.DATA_ID, 'dataType': indexDataUrl.DATA_TYPE},
                    success: function (res) {
                    }
                })
            }
        },
        getMenuList: function (event) {
            Ajax.request({
                url: 'menu/user',
                async: true,
                successCallback: function (data) {
                    vm.menuList = data.menuList;
                }
            });
        },
    },
    created: function () {
        var _this = this;
        _this.getMenuList();
        // _this.allDataTable();
        Ajax.request({
            url: '../sysMsg/queryMsgDataNum',
            async: true,
            successCallback: function (data) {
                for (var i = 0; i < data.list.length; i++) {
                    const dataResource1 = sysEnums.MSG_TYPE[data.list[i].TYPE];
                    const dataResource2 = data.list[i].TYPENUMBER;
                    const dataResource = {'TYPE': dataResource1, 'TYPENUMBER': dataResource2};
                    _this.data1.push(dataResource);
                }
            }
        })
    },
});
